package com.gxa.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.gxa.common.JsonResult;
import com.gxa.service.CustomerValueService;
import com.gxa.service.impl.CustomerValueServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/customerValue/search")
public class CustomerValueSearchServlet extends HttpServlet {
    /**
     * 按条件搜索客户价值
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取当前页码和每页显示条数
        Integer currentPage = Integer.parseInt(request.getParameter("page"));
//        System.out.println("调试1："+currentPage);
        Integer pageSize = Integer.parseInt(request.getParameter("limit"));
//        System.out.println("调试2："+pageSize);
        String customer_name = request.getParameter("customer_name");
//        System.out.println("调试3："+customer_name);
        String type = request.getParameter("type");
//        System.out.println("调试4："+type);
        //调用service
        CustomerValueService customerValueService = new CustomerValueServiceImpl();
        JsonResult jsonResult = customerValueService.searchCustomer(currentPage, pageSize, customer_name, type);
        //响应JsonResult
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(JSONObject.toJSONString(jsonResult));
    }
}
